from langgraph.func import task,entrypoint
from langgraph.checkpoint.memory import MemorySaver

@task
def task_one(item):
    """模拟任务1"""
    return f"任务一处理:{item}"

@task
def task_two(item):
    return f"任务二处理：{item}"

@entrypoint(checkpointer=MemorySaver())
def parallel_workflow(items:list) -> list:
    future = [task_one(item) for item in items]
    result_one = [f.result() for f in future]

    feture = [task_two(item) for item in items]
    results_two = [f.result() for f in future]

    return {"task_one":result_one,"task_two":results_two}

if __name__ == '__main__':
    config= {"configurable":{"thread_id":"parallel_workflow"}}
    items_to_process = ["item_a","item_b","item_c"]
    parallel_results = parallel_workflow.invoke(items_to_process,config)
    print(parallel_results)